package com.example.demo.service;

import com.example.demo.mapper.LogMapper;
import com.example.demo.model.LogInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

@Service
public class LogService {
    @Resource
    private LogMapper logMapper;

    @Transactional(propagation=Propagation.REQUIRED)
    public int add(LogInfo logInfo){
       int result=logMapper.add(logInfo);
        try {
            int num = 10 / 0;
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            result=0;
        }
        return result;
    }
}
